package com.rajaev.dtu.tractor.domain.repository.mysql;

import com.rajaev.dtu.tractor.domain.entity.RolePo;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface RoleDao {

    @Insert({
        "insert into t_role(role_name,create_datetime,delete_flag) values(#{roleName},sysdate(),'0')"
    })
    @Options(useGeneratedKeys = true,keyColumn = "id",keyProperty = "id")
    void insertRole(RolePo rolePo);

    @Select("select role_name as roleName,id from t_role where delete_flag = '0' and role_name = #{roleName}")
    RolePo selectRoleByName(String roleName);

    @Select({
            "select role_name as roleName,id from t_role where delete_flag = '0' and id = #{roleId}"
    })
    RolePo selectRoleById(@Param("roleId") Integer roleId);


    @Update("update t_role set delete_flag = '1' where id = #{roleId} ")
    void deleteRole(Integer roleId);

    List<RolePo> selectRoles();


    List<RolePo> selectRolesByUserId(Integer userId);

    void updateRole(@Param("rolePo") RolePo rolePo);
}
